<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>智慧写作平台</title>
<link href="/pad/resources/css/bootstrap.min.css" rel="stylesheet">
<link href="/pad/resources/css/style.css" rel="stylesheet">


</head>
<body>
	<nav class="navbar navbar-blue navbar-fixed-top" role="navigation">
		<div class="container bs-docs-container">
			<div class="navbar-header">
				<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-6">
					<span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span>
				</button>
				
				<h1>智慧写作平台</h1>
			</div>
			<ul class="nav navbar-nav">
				<li class="active"><a href="/pad">课程列表</a></li>
			</ul>
			<ul class="nav navbar-nav">
				<li id="watchIFbLi" class="active"><a href="#" onclick="getAsId('watch')">查看智能反馈</a></li>
			</ul>
			<ul class="nav navbar-nav">
				<li id="toLearnRseA" class="active"><a href="#" onclick="toLearnResource()">学习资源</a></li>
			</ul>
			<ul class="nav navbar-nav navbar-right">
				<li class="dropdown"><a id="user" href="#" class="dropdown-toggle" data-toggle="dropdown">用户 <span class="caret"></span></a>
					<ul class="dropdown-menu" role="menu">
						<li><a href="/pad/logout">退出登录</a></li>
					</ul></li>

			</ul>
     
		</div>
					
	</nav>
	  <button id="ctUAEditBtnId" style="display:none"  class="pull-right btn btn-info" data-toggle="modal" data-target="#createUserAdviceModal"><span class="glyphicon glyphicon-envelope"></span>&nbsp给系统提建议</button>
	<!-- 提建议 modal -->
	<div id="createUserAdviceModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">
						<span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
					</button>
					<h4 class="modal-title" id="myModalLabel">亲~给系统提个建议吧！</h4>
				</div>
				<div class="modal-body">
					<form id="createUserAdviceForm" role="form" action="/pad/userAdvice/saveUserAdvice" method="post">
						<input type="hidden" id="userIdInputId" name="userId">
						<input type="hidden"  id="realnameInputId" name="realname">
						<input type="hidden" id="activityIdInputId" name="activityId">
						<div class="form-group">
							<input class="form-control" name="advice" type="text" placeholder="系统不好用？给出你的建议吧。">
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button id="submitFbTpt" type="button" class="btn btn-info" onclick="submitAdviceForm('#createUserAdviceForm','#createUserAdviceModal');">创建</button>
				</div>
			</div>
		</div>
	</div>
	
	
	
	<div style="width:500px;margin-left:0px;">
	<!-- <div class="btn-group btn-group-justified" role="group" aria-label="..."> -->

    <!-- <button id="tp" type="button"  style="display:none"  class="btn  btn-info">获取最新版本的文本分析</button> -->

    <button id="pa" type="button" class="pull-right btn  btn-warning" onclick="getAsId('ays')">获取智能反馈</button>
     
   
	</div>

	
	
	
	<!-- <div class="container bs-docs-container"> -->
	
	
	    <div style="width:20%;float:left;margin-top:25px;">            
	        <div id="containRftDims" style="width:90%;float:left;margin-left:5%;"></div>   
	    </div>
	
	<!-- border:1px solid #F60; -->
		<div style="width:60%;float:left;">
		 
			<iframe id="editpad" src='#' width="100%" height="300" frameborder="no" border="0"></iframe>
		</div>
		
		
		
	    <div id="containScore"  style="width:20%;float:left;">
	   </div>
	
	
	<script src="/pad/resources/js/jquery.min.js"></script>
	<script src="/pad/resources/js/jquery.form.min.js"></script>
	<script src="/pad/resources/js/bootstrap.min.js"></script>
	
	 <div id="cprtFooter">
	        <!-- 版权信息 -->
	 </div>	

<script type="text/javascript">
		$("#cprtFooter").load("copyrightFooter.html");
</script>
	
	
	<script>
	
	function getQueryString(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
		var r = window.location.search.substr(1).match(reg);
		if (r != null)
			return unescape(r[2]);
		return null;
	}
	var student
	$.ajax({
		url : '/pad/getSessionUser',
		success : function(user) {
			student=user
			if(getQueryString('status')==0){
				$("#watchIFbLi").hide()
				$("#toLearnRseA").hide()
				$("#containRftDims").hide()
				$("#containScore").hide()
				$("#pa").hide()
			}
			
			
			$.ajax({
				url : '/pad/assignment/getAssignment?assignmentId='+getQueryString('assignmentId'),
				success : function(assignment) {
					if(assignment.rftDimTipTptId==null||assignment.rftDimTipTptId==''){//说明是 同伴互评不是反思写作，关闭反馈显示按钮
						
						$("#watchIFbLi").hide()
						$("#toLearnRseA").hide()
						$("#containRftDims").hide()
						$("#containScore").hide()
						$("#pa").hide()
					}
				}
			})
			
		}
	})
	 
	function toLearnResource(){
		var  toLearnResourceEvent={} 
		toLearnResourceEvent["userId"]=student.id;
		toLearnResourceEvent["activityId"]=getQueryString('activityId');
		toLearnResourceEvent["object"]="btn_toLearnResource";
		toLearnResourceEvent["action"]="进入学习资源页面";
		 $.ajax({
			   url: "/pad/event/saveRftWritingEvent",
			   type: 'POST',
			   data:toLearnResourceEvent,
			   async: false,
			   dataType: "json", //返回数据格式为json
			   success: function(data) {//请求成功完成后要执行的方法
			   
			   }
		 });
		
		 var assignment_Id;
		 var activity_Id;
		 assignment_Id=getQueryString('assignmentId')
  	     activity_Id=getQueryString('activityId')
  	     
  	     //window.location.href="/pad/learnResource/index.html?assignmentId="+assignment_Id+"&activityId="+activity_Id
  	     window.open("/pad/learnResource/index.html?assignmentId="+assignment_Id+"&activityId="+activity_Id)	
	}
	
	function myfun(dimName){
		var  toLearnResourceEvent={} 
		toLearnResourceEvent["userId"]=student.id;
		toLearnResourceEvent["activityId"]=getQueryString('activityId');
		toLearnResourceEvent["object"]="a_toNotWellDimLearnResource";
		toLearnResourceEvent["action"]="看到得分不佳反思维度，点击维度链接进入学习，得分不佳不可以进入下一个活动";
		 $.ajax({
			   url: "/pad/event/saveRftWritingEvent",
			   type: 'POST',
			   data:toLearnResourceEvent,
			   async: false,
			   dataType: "json", //返回数据格式为json
			   success: function(data) {//请求成功完成后要执行的方法
			   
			   }
		 });
		
		//js 传参只能 传字符串类型   用             '\''  表示  一个  '
		window.open(encodeURI("/pad/rftResource/index.html?dimName="+encodeURI(dimName)));
	}
	
	
	/**
	 * 提交表单
	 */
	function submitAdviceForm(formSelecter,modalSelecter){
		$("#userIdInputId").attr("value",student.id)
		$("#realnameInputId").attr("value",student.realname)
		$("#activityIdInputId").attr("value",getQueryString('activityId'))
		// 异步提交表单
	    $(formSelecter).ajaxSubmit({  
	        type:'post',
	        resetForm: true,
	        success:function(data){ 
	        		$(modalSelecter).modal('hide');
	        		var userGiveAdviceInEditEvent={} 
	        		userGiveAdviceInEditEvent["userId"]=student.id;
	        		userGiveAdviceInEditEvent["activityId"]=getQueryString('activityId');
	        		userGiveAdviceInEditEvent["object"]="btn_editUserAdvice";
	        		userGiveAdviceInEditEvent["action"]="用户在编辑页面给系统提建议了";
	        		 $.ajax({
	        			   url: "/pad/event/saveRftWritingEvent",
	        			   type: 'POST',
	        			   data:userGiveAdviceInEditEvent,
	        			   async: false,
	        			   dataType: "json", //返回数据格式为json
	        			   success: function(data) {//请求成功完成后要执行的方法
	        			   }
	        		 });
	        },
	        error:function(msg){
	        	alert(msg.statusText);
	        }
	    });  
	}
	
	
	
	 function getAsId(watchOrAys){
 		 var assignment_Id;
 		 var activity_Id;
  	     assignment_Id=getQueryString('assignmentId')
  	     activity_Id=getQueryString('activityId') 
  	     
  	   window.location.href="/pad/rftTextAnalyse.html?assignmentId="+assignment_Id+"&activityId="+activity_Id+"&watchOrAys="+watchOrAys 
  	   //window.location.href="/pad/textAnalyse.html?assignmentId="+assignment_Id+"&activityId="+activity_Id   
	 }
		document.cookie="activityId="+getQueryString('activityId')+";path=/";
		function getQueryString(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
			var r = window.location.search.substr(1).match(reg);
			if (r != null)
				return unescape(r[2]);
			return null;
		}
		$.ajax({
			url : '/pad/getSessionUser',
			success : function(user) {
				$.ajax({
					url : '/pad/assignment/getAssignmentPadCurrentId?assignmentId='
							+ getQueryString('assignmentId'),
					success : function(data) {
						//console.log(data)
						$("#editpad").attr("height", $(window).height() - 95);
						$("#editpad").attr(
								"src",
								"http://localhost:8081/p/" + data.id
										+ "?userName=" + user.realname);
						if(data.asType=="1"){
							//个人作业，有反思
							
							$("#containRftDims").append('<h4><div class="alert alert-info" role="alert">请参考以下反思写作提示问题,在右侧编辑区域完成你的反思写作。</div></h4>');
							
						
							var rftDimTips=data.rftDimTips
							
							for(var i=0;i<rftDimTips.length;i=i+1){
							$("#containRftDims").append('<div class="panel panel-info"><div class="panel-heading"><h3 class="panel-title">'+rftDimTips[i].dimName+'</h3></div><div class="panel-body">'+rftDimTips[i].tips+'</div></div>')	
							}
							$.ajax({
								async: false,
								url:'/pad/reflection/getStuRftScore?studentId='+user.id+'&assignmentId='+getQueryString('assignmentId'),
								success:function(data){
									if(data.score.length>0){
									$("#containScore").append('<h4><div class="alert alert-info" role="alert">你在本次反思写作作业的得分如下:</div></h4>');
									var hasOne=false;
									for(var i=0;i<data.score.length;i++){
										for(var j=0;j<data.rftDims.length;j++){
											if(data.score[i].rftDimId==data.rftDims[j].id){
												if(data.score[i].score<data.rftDims[j].passScore){
												 hasOne=true;
											    }
										    }
										}
									}	
									
									if(hasOne){
										$("#containScore").append('<div class="alert alert-danger" role="alert">注意，红色显示的反思维度名称表示在反思维度上得分未及格，请参照教师反馈建议认真修改，否则将不能进入下一部分进行学习!</div>');
									}
									
									for(var i=0;i<data.score.length;i++){
										for(var j=0;j<data.rftDims.length;j++){
											if(data.score[i].rftDimId==data.rftDims[j].id){
												$("#containScore").append('<ul id="'+data.score[i].rftDimId+'" class="list-group"></ul>');
													if(data.score[i].score>=data.rftDims[j].passScore){//及格了 用绿色 不及格用红色
												$('#'+data.score[i].rftDimId+'').append('<li class="list-group-item list-group-item-success">'+data.rftDims[j].dimName+'&nbsp(满分为:'+data.rftDims[j].dimScore+'分)</li>');
												$('#'+data.score[i].rftDimId+'').append('<li class="list-group-item list-group-item-warning">得分:&nbsp'+data.score[i].score+'</li>');
												$('#'+data.score[i].rftDimId+'').append('<li class="list-group-item list-group-item-info">反馈:&nbsp'+data.score[i].comment+'</li>');
												}else{
													$('#'+data.score[i].rftDimId+'').append('<li class="list-group-item list-group-item-danger">'+data.rftDims[j].dimName+'&nbsp(满分为:'+data.rftDims[j].dimScore+'分)</li>');
													$('#'+data.score[i].rftDimId+'').append('<li class="list-group-item list-group-item-warning">得分:&nbsp'+data.score[i].score+'</li>');
													$('#'+data.score[i].rftDimId+'').append('<li class="list-group-item list-group-item-info">反馈:&nbsp'+data.score[i].comment+'</li>');
													$('#'+data.score[i].rftDimId+'').append('<a href="#" class="list-group-item list-group-item-danger" onclick="myfun('+'\''+data.rftDims[j].dimName+'\''+')">点击这里进行学习</a>');
												}
												
																							
											}
										}
										
									}
									}
									
								}});
						}
						
						
						
					}
				});
				$("#user").html(user.realname);
			}
		});
	</script>
</body>
</html>
